
;;problemas para resolver
;;No aparece el icono
;;he tenido que quitar dos mensajes del archivo transobj1.lsp marcados como PV
;;las transformaciones dan como resultado siempre objetos de datos multivariados

(defun dialog-search-replace ()
  (setf search 
        (send edit-text-item-proto 
              :new "" :text-length 15))
  (setf replace
        (send edit-text-item-proto 
              :new "" :text-length 15))
  (setf cancel 
        (send button-item-proto :new "Cancel"
              :action #'(lambda ()
                          (send dialog :close)
                          )))
  (setf OK 
        (send button-item-proto 
              :new "Replace"
              :action #'(lambda ()
                          (search-replace
                           (with-input-from-string (s (send search :text)) (read s))
                           (with-input-from-string (s (send replace :text)) (read s)))
                          (send dialog :close)
                          )))

  (setf dialog
        (send modal-dialog-proto :new
              (list "Search for"
                    (list search)
                    (list "Replace for")
                    (list replace)
                    (list OK cancel))
              ))
  )

 (defun search-replace2 (&optional search replace)
   (if (and search replace)       
       (transform 
       :name (concatenate 'string "Ser_Rep_" (send current-data :name)) ;does not work as explained in transf0.lsp
        :use current-data
        :program 
        (mapcar #'(lambda (variable) 
                    (map-elements #'(lambda (datatoreplace)
                                      (cond
                                        ((stringp datatoreplace)
                                         (if (equal (string-upcase (princ-to-string search))
                                                    (string-upcase datatoreplace))
                                             (princ-to-string replace)
                                             datatoreplace))
                                        ((and
                                          (numberp datatoreplace)
                                          (numberp search))
                                         (if (= datatoreplace search) 
                                             replace
                                             datatoreplace))
                                        ((not datatoreplace)
                                         (if (equal search datatoreplace)
                                             replace
                                             datatoreplace))
                                        (t datatoreplace)
                                        ))
                                  variable))
                (column-list (send current-data :active-data-matrix '(all))))
        :variables (send current-data :active-variables '(all))
        :types (send current-data :types)
       ; :data-type (send current-data :data-type) ;this does not work as explained in the transf0.lsp file
        )
       (dialog-search-replace)
   ))


 (defun Search-Replace (search replace)
   "Replaces values and creates a data object with the new data"
        (data (send current-data :name)          
              :created  (send *desktop* :selected-icon)          
              :title     (send current-data :title)
              :variables (send current-data :active-variables '(all))  
              :data      (mapcar #'(lambda (datatoreplace)
                                     (cond
                                       ((stringp datatoreplace)
                                        (if (equal (string-upcase (princ-to-string search))
                                                   (string-upcase datatoreplace))
                                            (princ-to-string replace)
                                            datatoreplace))
                                       ((and
                                        (numberp datatoreplace)
                                         (numberp search))
                                        (if (= datatoreplace search) 
                                            replace
                                            datatoreplace))
                                       ((not datatoreplace)
                                        (if (equal search datatoreplace)
                                            replace
                                            datatoreplace))
                                       (t datatoreplace)
                                       ))
                                     (send current-data :active-data '(all)))
              :labels    (send current-data :active-labels)
              :types     (send current-data :active-types '(all)))
    )
